// pages/admin/admin.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    data: [],
    list: [],
    changedList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    let that = this;
    app.login().then(function() {
      let cookie = wx.getStorageSync('cookieKey');
      let header = {};
      if (cookie) {
        header.Cookie = cookie;
      }
      wx.request({
        url: app.globalData.url + '/wxapp/change_score',
        header: header,
        data: {
          type: 'all'
        },
        success: function(res) {
          console.log(res.data)
          that.setData({
            list: res.data
          })
          wx.showToast({
            title: "修改成功！",
            duration: 3000
          })
        },
        fail: function(res) {}
      })


      that.setData({
        teamPre: app.globalData.teamPre,
        data: app.globalData.data,
      })
      console.log(that.data.data)
    })
  },
  inputChange: function(e) {
    let that = this
    var newList = that.data.list;
    for (let x in that.data.list) {
      if (parseInt(that.data.list[x][0]) == parseInt(e.target.id)) {
        newList[x][3] = e.detail.value
      }
    }
    this.setData({
      changedList: newList
    })
  },
  change: function() {
    let that = this
    let cookie = wx.getStorageSync('cookieKey');
    let header = {};
    if (cookie) {
      header.Cookie = cookie;
    }
    wx.request({
      url: app.globalData.url + '/wxapp/change_score',
      header: header,
      data: {
        type: 'list',
        list: that.data.list
      },
      success: function(res) {
        console.log(res)
        that.setData({
          list: res.data
        })
      },
      fail: function(res) {
        console.log(res)
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})